package com.clkj.xiuzheng.controller.adv;

import com.clkj.xiuzheng.pojo.Setting;
import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author yawang
 * @create 2024/04/28 10:56:48
 **/
@RestController
@RequestMapping(value = "/setting")
@Api(value = "/setting", tags = {"设置管理"})
@CrossOrigin
public class SettingController {
    @Autowired
    private ShopService shopService;

    @ApiOperation(value = "新增或修改设置")
    @PostMapping("/addOrUpdateSetting")
    public Result addOrUpdateSetting(Setting setting){
        try {
            shopService.addOrUpdateSetting(setting);
            return new Result(true, StatusCode.OK,"查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation(value = "获取设置")
    @PostMapping("/listSetting")
    public Result listSetting(){
        try {
            Setting setting = shopService.listSetting();
            return new Result(true, StatusCode.OK,"查询成功",setting);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

}
